package com.boost.socialNetwork.client;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;

public class SideBar extends VerticalPanel {

	private final UserServiceAsync greetService = GWT
	.create(UserService.class);
	
	public SideBar() {
		
		Label newIdea = new Label("New Idea");
		newIdea.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				HistoryManager.newHistory("PageIdeaEntry");
//				IdeaEntry idea = new IdeaEntry();				
//				RootPanel.get("post").clear();
//				RootPanel.get("head").clear();				
//				RootPanel.get("post").add(idea);
//				RootPanel.get("head").add(idea.getHead());
			}
		});
		
		Label lblHome = new Label("Home");
		lblHome.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {			
//				RootPanel.get("post").clear();
//				RootPanel.get("head").clear();
//				Home home = new Home();
//				RootPanel.get("post").add(home);
//				RootPanel.get("head").add(home.getHead());
				HistoryManager.newHistory("PageHome");
			}
		});
		lblHome.setStyleName("gwt-LabelLink");
		add(lblHome);
		
		
		newIdea.setStyleName("gwt-LabelLink");
		add(newIdea);
				
		
		Label lblNewLabel = new Label("Logout");
		lblNewLabel.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				greetService.logout(new AsyncCallback<String>() {
					
					@Override
					public void onSuccess(String result) {
//						RootPanel.get("post").clear();
//						RootPanel.get("head").clear();
//						RootPanel.get("sidebar").clear();
//						Login login = new Login();										
//						RootPanel.get("head").add(login.getHead());
//						RootPanel.get("post").add(login);						
						HistoryManager.newHistory("PageLogin");
					}
					
					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						
					}
				});
			}
		});
		lblNewLabel.setStyleName("gwt-LabelLink");
		add(lblNewLabel);
		
	}
}
